<?php
	class Rating extends Model {
		function Rating() {
			parent::Model();
		}
		function get_doctor_details($id){
			if (!is_numeric($id))
				return false;
		
			$query = $this->db->getwhere('users', array('id' => $id, 'acc_type' => 'doctor'));
			$data = $query->result_array();

			if(empty($data))
				return false;
			else {
				$query = $this->db->getwhere('rating_comments', array('id_user' => $id));
				$data['comments'] = $query->result_array();
				for ($i=0; $i<count($data['comments']); $i++){
					$query = $this->db->getwhere('users', array('id' => $data['comments'][$i]['id_rater']));
					$data['comments'][$i]['rater_userinfo'] = $query->result_array();;
					
					$query = $this->db->getwhere('rating_items');
					$data['comments'][$i]['rating'] = $query->result_array();
					
					for ($j=0; $j<count($data['comments'][$i]['rating']); $j++){
						$where = array(	'id_comment' => $data['comments'][$i]['id'], 
										'id_item' => $data['comments'][$i]['rating'][$j]['id']);
						$query = $this->db->getwhere('rating_data', $where);
						$r = $query->result_array();
						$data['comments'][$i]['rating'][$j]['value'] = $r[0]['value'];
					}
				}
				return $data;
			}
        }
	}
?>